package com.sunma.repair.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sunma.common.annotation.Log;
import com.sunma.common.core.controller.BaseController;
import com.sunma.common.core.domain.AjaxResult;
import com.sunma.common.enums.BusinessType;
import com.sunma.repair.domain.AssetsRepair;
import com.sunma.repair.service.IAssetsRepairService;
import com.sunma.common.utils.poi.ExcelUtil;
import com.sunma.common.core.page.TableDataInfo;

/**
 * 资产报修Controller
 * 
 * @author sunma
 * @date 2024-07-12
 */
@RestController
@RequestMapping("/repair/repair")
public class AssetsRepairController extends BaseController
{
    @Autowired
    private IAssetsRepairService assetsRepairService;

    /**
     * 查询资产报修列表
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:list')")
    @GetMapping("/list")
    public TableDataInfo list(AssetsRepair assetsRepair)
    {
        startPage();
        List<AssetsRepair> list = assetsRepairService.selectAssetsRepairList(assetsRepair);
        return getDataTable(list);
    }

    /**
     * 导出资产报修列表
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:export')")
    @Log(title = "资产报修", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AssetsRepair assetsRepair)
    {
        List<AssetsRepair> list = assetsRepairService.selectAssetsRepairList(assetsRepair);
        ExcelUtil<AssetsRepair> util = new ExcelUtil<AssetsRepair>(AssetsRepair.class);
        util.exportExcel(response, list, "资产报修数据");
    }

    /**
     * 获取资产报修详细信息
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetsRepairService.selectAssetsRepairById(id));
    }

    /**
     * 新增资产报修
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:add')")
    @Log(title = "资产报修", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AssetsRepair assetsRepair)
    {
        return toAjax(assetsRepairService.insertAssetsRepair(assetsRepair));
    }

    /**
     * 修改资产报修
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:edit')")
    @Log(title = "资产报修", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AssetsRepair assetsRepair)
    {
        return toAjax(assetsRepairService.updateAssetsRepair(assetsRepair));
    }

    /**
     * 删除资产报修
     */
    @PreAuthorize("@ss.hasPermi('repair:repair:remove')")
    @Log(title = "资产报修", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetsRepairService.deleteAssetsRepairByIds(ids));
    }
}
